﻿// fct_test_l170qm_one.cpp: 实现文件
//

#include "pch.h"
#include "MFCApplication1.h"
#include "afxdialogex.h"
#include "fct_test_l170qm_one.h"
#include "logout.h"
#include "commom.h"
#include "SelfTime.h"


// fct_test_l170qm_one 对话框
fct_test_l170qm_one* pfct_test_l170qm_one = NULL;
IMPLEMENT_DYNAMIC(fct_test_l170qm_one, CDialogEx)

fct_test_l170qm_one::fct_test_l170qm_one(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_MFC_L170QM_ONE, pParent)
{
	pfct_test_l170qm_one = this;
	int channelNum = 4;

}

fct_test_l170qm_one::~fct_test_l170qm_one()
{
	//multiSerialPort.~MultiSerialPort();
	pfct_test_l170qm_one = NULL;

	USER_PRINTF_LOG(LOG_FILE, "fct_test_l170qm_one exit");
	
}

void fct_test_l170qm_one::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_PROGRESS_L170QM_ONE, m_ProgressCtrl);
}

BEGIN_MESSAGE_MAP(fct_test_l170qm_one, CDialogEx)

END_MESSAGE_MAP()


// fct_test_l170qm_one 消息处理程序
BOOL fct_test_l170qm_one::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	m_ProgressCtrl.SetBkColor(RGB(255, 245, 238));
	m_ProgressCtrl.SetBarColor(RGB(0, 255, 0));
	m_ProgressCtrl.SetRange(0, 100);
	m_ProgressCtrl.SetPos(0);
	m_ProgressCtrl.SetStep(0);
	m_ProgressCtrl.StepIt();


	return TRUE;  // 返回 TRUE，除非将焦点设置到控件
}


/************************* 工具存放区 *****************************/
/************************* 工具存放区 *****************************/
/************************* 工具存放区 *****************************/
bool fct_test_l170qm_one::sendDataL170(int channel, char* data, int len) {

	return true;
}

void fct_test_l170qm_one::viewlog(std::string log) {

	SelfTimeTools timerTools;
	std::string time = timerTools.GetSelfCurrentTime();
	view = view + "[" + CString(time.c_str()) + "] " + CString(log.c_str()) + "\r\n";

	GetDlgItem(IDC_L170QM_LOG_STATUS_OUTPUT_ONE)->SetWindowText(view);
	CEdit* pViewPortRecv = (CEdit*)GetDlgItem(IDC_L170QM_LOG_STATUS_OUTPUT_ONE);
	pViewPortRecv->LineScroll(pViewPortRecv->GetLineCount());
	int nLength = pViewPortRecv->GetWindowTextLength();
	pViewPortRecv->SetSel(nLength, nLength, SCF_SELECTION);
}

void fct_test_l170qm_one::clearlog() {
	view = _T("");
	view.Empty();
}

//重写虚函数PreTranslateMessage() 用于回车键确认
BOOL fct_test_l170qm_one::PreTranslateMessage(MSG* pMsg)
{
	// TODO:  在此添加专用代码和/或调用基类
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
	{
		if (GetFocus()->GetDlgCtrlID() == IDC_EDIT_L170QM_IMEI_INPUT)//按下回车，如果当前焦点是在自己期望的控件上
		{
			// 你想做的事，如果按下回车时焦点在你想要的控件上
			test_l170qm_Task();
		}
		return TRUE;
	}
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE)
		return TRUE;
	return CDialogEx::PreTranslateMessage(pMsg);
}

/************************* AT指令回调存放区 *****************************/
/************************* AT指令回调存放区 *****************************/
/************************* AT指令回调存放区 *****************************/
static int devAtSend(int channel, char* data, int len)
{
	if (pfct_test_l170qm_one == NULL)
		return 0;

	if (pfct_test_l170qm_one->sendDataL170(channel, data, len));
		return 1;
	return 0;
}

static int devAtReady(int channel, char* data, int len)
{
	char* p = mystrstr(data, "OK");
	if (p != NULL) {
		return 1;
	}
	return 0;
}

//static fct_at_cmd_obj_t at_test_command[] = {
//	{"AT\r\n", "AT测试", 0, devAtSend, devAtReady, 1, 3},
//	{"AT*PROD=1\r\n", "切换工厂模式", 0, devAtSend, devAtReady, 2, 3},
//	{"AT*CALINFO=R,LteCal\r\n", "检测Lte", 0, devAtSend, devAtReady, 3, 3},
//	{"AT*CALINFO=R,WcdmaCal\r\n", "检测Wcdma", 0, devAtSend, devAtReady, 4, 3},
//	{"AT*CALINFO=R,GsmCal\r\n", "检测Gsm", 0, devAtSend, devAtReady, 5, 3},
//	{"AT*MRD_IMEI=D\r\n", "擦除原有的IMEI号", 0, devAtSend, devAtReady, 6, 3},
//	{"AT*MRD_IMEI=\r\n", "写IMEI号", 0, devAtSend, devAtReady, 7, 3},           // 需要配置
//	{"AT*PROD=0\r\n", "解除工厂模式", 0, devAtSend, devAtReady, 8, 3},
//	{"AT*PROD?\r\n", "查看当前模式", 0, devAtSend, devAtReady, 9, 3},
//	{"AT+CGSN\r\n", "获取IMEI", 0, devAtSend, devAtReady, 10, 3},
//	{"AT+CPIN?\r\n", "查卡", 0, devAtSend, devAtReady, 11, 3},
//	{"AT+CSQ\r\n", "信号强度", 0, devAtSend, devAtReady, 12, 3},
//	{"ATI\r\n", "获取版本号", 0, devAtSend, devAtReady, 13, 3},
//	{"AT\r\n", "结束测试", 0, devAtSend, devAtReady, 99, 3},
//
//};


/************************* AT指令结构存放区 *****************************/
/************************* AT指令结构存放区 *****************************/
/************************* AT指令结构存放区 *****************************/
static fct_at_cmd_obj_t at_test_command[] = {
	{"AT\r\n", "AT测试", 0, devAtSend, devAtReady, 1, 7},
	{"ATI\r\n", "切换工厂模式", 0, devAtSend, devAtReady, 2, 7},
	{"AT\r\n", "检测Lte", 0, devAtSend, devAtReady, 3, 7},
	{"ATI\r\n", "检测Wcdma", 0, devAtSend, devAtReady, 4, 7},
	{"AT\r\n", "检测Gsm", 0, devAtSend, devAtReady, 5, 7},
	{"ATI\r\n", "擦除原有的IMEI号", 0, devAtSend, devAtReady, 6, 7},
	{"AT\r\n", "写IMEI号", 0, devAtSend, devAtReady, 7, 7},
	{"ATI\r\n", "解除工厂模式", 0, devAtSend, devAtReady, 8, 7},
	{"AT\r\n", "查看当前模式", 0, devAtSend, devAtReady, 9, 7},
	{"AT+CGSN\r\n", "获取IMEI", 0, devAtSend, devAtReady, 10, 7},
	{"ATI\r\n", "查卡", 0, devAtSend, devAtReady, 11, 7},
	{"AT\r\n", "信号强度", 0, devAtSend, devAtReady, 12, 7},
	{"ATI\r\n", "获取版本号", 0, devAtSend, devAtReady, 13, 7},
	{"AT\r\n", "结束测试", 0, devAtSend, devAtReady, 99, 7},

};

static int at_cmd_total = \
		sizeof(at_test_command) / sizeof(at_test_command[0]);




/************************* 上位机任务存放区 *****************************/
/************************* 上位机任务存放区 *****************************/
/************************* 上位机任务存放区 *****************************/


/*
	任务启动，扫码启动
*/
void fct_test_l170qm_one::test_l170qm_Task() {


}
